
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.abinit.variable &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.variable</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.abinit.variable</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">string</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>


<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s1">&#39;InputVariable&#39;</span><span class="p">,</span>
<span class="p">]</span>

<span class="n">_SPECIAL_DATASET_INDICES</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;:&#39;</span><span class="p">,</span> <span class="s1">&#39;+&#39;</span><span class="p">,</span> <span class="s1">&#39;?&#39;</span><span class="p">)</span>

<span class="n">_DATASET_INDICES</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">digits</span><span class="p">)</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">_SPECIAL_DATASET_INDICES</span><span class="p">))</span>

<span class="n">_INTERNAL_DATASET_INDICES</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;__s&#39;</span><span class="p">,</span> <span class="s1">&#39;__i&#39;</span><span class="p">,</span> <span class="s1">&#39;__a&#39;</span><span class="p">)</span>

<span class="n">_SPECIAL_CONVERSION</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="n">_INTERNAL_DATASET_INDICES</span><span class="p">,</span> <span class="n">_SPECIAL_DATASET_INDICES</span><span class="p">)</span>

<span class="n">_UNITS</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;bohr&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span>
    <span class="s1">&#39;angstrom&#39;</span><span class="p">:</span> <span class="mf">1.8897261328856432</span><span class="p">,</span>
    <span class="s1">&#39;hartree&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span>
    <span class="s1">&#39;Ha&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span>
    <span class="s1">&#39;eV&#39;</span><span class="p">:</span> <span class="mf">0.03674932539796232</span><span class="p">,</span>
<span class="p">}</span>


<div class="viewcode-block" id="InputVariable"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.variable.html#pymatgen.io.abinit.variable.InputVariable">[docs]</a><span class="k">class</span> <span class="nc">InputVariable</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    An Abinit input variable.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">units</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">valperline</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_units</span> <span class="o">=</span> <span class="n">units</span>

        <span class="c1"># Maximum number of values per line.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">valperline</span> <span class="o">=</span> <span class="n">valperline</span>
        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;bdgw&#39;</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">valperline</span> <span class="o">=</span> <span class="mi">2</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">is_iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="ow">in</span> <span class="n">_UNITS</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_units</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

<div class="viewcode-block" id="InputVariable.get_value"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.variable.html#pymatgen.io.abinit.variable.InputVariable.get_value">[docs]</a>    <span class="k">def</span> <span class="nf">get_value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the value.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">units</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> <span class="o">+</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">units</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">basename</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the name trimmed of any dataset index.&quot;&quot;&quot;</span>
        <span class="n">basename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
        <span class="k">return</span> <span class="n">basename</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="n">_DATASET_INDICES</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">dataset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the dataset index in string form.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">basename</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">units</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the units.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_units</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Declaration of the variable in the input file.&quot;&quot;&quot;</span>
        <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span>
        <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
            <span class="k">return</span> <span class="s1">&#39;&#39;</span>

        <span class="n">var</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
        <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="n">var</span>

        <span class="c1"># By default, do not impose a number of decimal points</span>
        <span class="n">floatdecimal</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="c1"># For some inputs, enforce number of decimal points...</span>
        <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">inp</span> <span class="ow">in</span> <span class="n">var</span> <span class="k">for</span> <span class="n">inp</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;xred&#39;</span><span class="p">,</span> <span class="s1">&#39;xcart&#39;</span><span class="p">,</span> <span class="s1">&#39;rprim&#39;</span><span class="p">,</span> <span class="s1">&#39;qpt&#39;</span><span class="p">,</span> <span class="s1">&#39;kpt&#39;</span><span class="p">)):</span>
            <span class="n">floatdecimal</span> <span class="o">=</span> <span class="mi">16</span>

        <span class="c1"># ...but not for those</span>
        <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">inp</span> <span class="ow">in</span> <span class="n">var</span> <span class="k">for</span> <span class="n">inp</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;ngkpt&#39;</span><span class="p">,</span> <span class="s1">&#39;kptrlatt&#39;</span><span class="p">,</span> <span class="s1">&#39;ngqpt&#39;</span><span class="p">,</span> <span class="s1">&#39;ng2qpt&#39;</span><span class="p">)):</span>
            <span class="n">floatdecimal</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
            <span class="n">n</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
                <span class="n">n</span> <span class="o">*=</span> <span class="n">i</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
            <span class="n">value</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

        <span class="c1"># values in lists</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>

            <span class="c1"># Reshape a list of lists into a single list</span>
            <span class="k">if</span> <span class="nb">all</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">value</span><span class="p">):</span>
                <span class="n">line</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_list2d</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_list</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="p">)</span>

        <span class="c1"># scalar values</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">+=</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

        <span class="c1"># Add units</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">units</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">+=</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">units</span>

        <span class="k">return</span> <span class="n">line</span>

<div class="viewcode-block" id="InputVariable.format_scalar"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.variable.html#pymatgen.io.abinit.variable.InputVariable.format_scalar">[docs]</a>    <span class="k">def</span> <span class="nf">format_scalar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Format a single numerical value into a string</span>
<span class="sd">        with the appropriate number of decimal.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sval</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">sval</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s1">&#39;+&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">isdigit</span><span class="p">()</span> <span class="ow">and</span> <span class="n">floatdecimal</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">sval</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">fval</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">sval</span>

        <span class="k">if</span> <span class="n">fval</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">fval</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">1e-3</span> <span class="ow">and</span> <span class="nb">abs</span><span class="p">(</span><span class="n">fval</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">1e4</span><span class="p">):</span>
            <span class="n">form</span> <span class="o">=</span> <span class="s1">&#39;f&#39;</span>
            <span class="n">addlen</span> <span class="o">=</span> <span class="mi">5</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">form</span> <span class="o">=</span> <span class="s1">&#39;e&#39;</span>
            <span class="n">addlen</span> <span class="o">=</span> <span class="mi">8</span>

        <span class="n">ndec</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">fval</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">fval</span><span class="p">)))</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="p">)</span>
        <span class="n">ndec</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">ndec</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>

        <span class="n">sval</span> <span class="o">=</span> <span class="s1">&#39;{v:&gt;</span><span class="si">{l}</span><span class="s1">.</span><span class="si">{p}{f}</span><span class="s1">}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">v</span><span class="o">=</span><span class="n">fval</span><span class="p">,</span> <span class="n">l</span><span class="o">=</span><span class="n">ndec</span><span class="o">+</span><span class="n">addlen</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="n">ndec</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="n">form</span><span class="p">)</span>

        <span class="n">sval</span> <span class="o">=</span> <span class="n">sval</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;e&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">sval</span></div>

<div class="viewcode-block" id="InputVariable.format_list2d"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.variable.html#pymatgen.io.abinit.variable.InputVariable.format_list2d">[docs]</a>    <span class="k">def</span> <span class="nf">format_list2d</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Format a list of lists.&quot;&quot;&quot;</span>
        <span class="n">lvals</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>

        <span class="c1"># Determine the representation</span>
        <span class="k">if</span> <span class="nb">all</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">lvals</span><span class="p">):</span>
            <span class="n">type_all</span> <span class="o">=</span> <span class="nb">int</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">lvals</span><span class="p">:</span>
                    <span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                <span class="n">type_all</span> <span class="o">=</span> <span class="nb">float</span>
            <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                <span class="n">type_all</span> <span class="o">=</span> <span class="nb">str</span>

        <span class="c1"># Determine the format</span>
        <span class="n">width</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">s</span><span class="p">))</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">lvals</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">type_all</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
            <span class="n">formatspec</span> <span class="o">=</span> <span class="s1">&#39;&gt;</span><span class="si">{0}</span><span class="s1">d&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">type_all</span> <span class="o">==</span> <span class="nb">str</span><span class="p">:</span>
            <span class="n">formatspec</span> <span class="o">=</span> <span class="s1">&#39;&gt;</span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>

            <span class="c1"># Number of decimal</span>
            <span class="n">maxdec</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">f</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">f</span><span class="p">)))</span><span class="o">-</span><span class="mi">2</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">lvals</span><span class="p">)</span>
            <span class="n">ndec</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">maxdec</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="p">),</span> <span class="mi">10</span><span class="p">)</span>

            <span class="k">if</span> <span class="nb">all</span><span class="p">(</span><span class="n">f</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">1e-3</span> <span class="ow">and</span> <span class="nb">abs</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">1e4</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">lvals</span><span class="p">):</span>
                <span class="n">formatspec</span> <span class="o">=</span> <span class="s1">&#39;&gt;</span><span class="si">{w}</span><span class="s1">.</span><span class="si">{p}</span><span class="s1">f&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">w</span><span class="o">=</span><span class="n">ndec</span><span class="o">+</span><span class="mi">5</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="n">ndec</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">formatspec</span> <span class="o">=</span> <span class="s1">&#39;&gt;</span><span class="si">{w}</span><span class="s1">.</span><span class="si">{p}</span><span class="s1">e&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">w</span><span class="o">=</span><span class="n">ndec</span><span class="o">+</span><span class="mi">8</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="n">ndec</span><span class="p">)</span>

        <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="k">for</span> <span class="n">L</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">L</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">+=</span> <span class="s1">&#39; {v:</span><span class="si">{f}</span><span class="s1">}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">v</span><span class="o">=</span><span class="n">val</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="n">formatspec</span><span class="p">)</span>
            <span class="n">line</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>

        <span class="k">return</span> <span class="n">line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="InputVariable.format_list"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.variable.html#pymatgen.io.abinit.variable.InputVariable.format_list">[docs]</a>    <span class="k">def</span> <span class="nf">format_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Format a list of values into a string.</span>
<span class="sd">        The result might be spread among several lines.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>

        <span class="c1"># Format the line declaring the value</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">values</span><span class="p">):</span>
            <span class="n">line</span> <span class="o">+=</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_scalar</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">floatdecimal</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">valperline</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">valperline</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>

        <span class="c1"># Add a carriage return in case of several lines</span>
        <span class="k">if</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">):</span>
            <span class="n">line</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="n">line</span>

        <span class="k">return</span> <span class="n">line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span></div></div>


<span class="k">def</span> <span class="nf">is_iter</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Return True if the argument is list-like.&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s1">&#39;__iter__&#39;</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">flatten</span><span class="p">(</span><span class="n">iterable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make an iterable flat, i.e. a 1d iterable object.&quot;&quot;&quot;</span>
    <span class="n">iterator</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">iterable</span><span class="p">)</span>
    <span class="n">array</span><span class="p">,</span> <span class="n">stack</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">deque</span><span class="p">(),</span> <span class="n">collections</span><span class="o">.</span><span class="n">deque</span><span class="p">()</span>
    <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">value</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="n">iterator</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">stack</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">array</span><span class="p">)</span>
            <span class="n">iterator</span> <span class="o">=</span> <span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> \
               <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">):</span>
                <span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">iterator</span><span class="p">)</span>
                <span class="n">iterator</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">array</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.variable</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>